CC = gcc
CFLAGS = -g -Wall -O0

bin_dir := build
obj_dir := build

srcs := instr.c simu8051.c test.c tools.c mem.c kbhit.c main.c
objects := $(patsubst %.c,$(obj_dir)/%.o,$(srcs))
target := $(bin_dir)/app

all : $(target)

$(target) : $(objects)
	@mkdir -p $(@D)
	$(CC) $(CFLAGS) $^ -o $@

$(obj_dir)/%.o : %.c
	@mkdir -p $(@D)
	$(CC) $(CFLAGS) -c $< -o $@

.PHONY : clean
clean :
	rm -rf $(obj_dir)